﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace Spore.Validator
{
    /// <summary>
    /// 正则表达式验证器
    /// </summary>
   public class ValidatorRegex:ValidatorBase
    {
        /// <summary>
        /// 正则表达式对象
        /// </summary>
        private Regex mRegex;

        /// <summary> 
        /// </summary> 
        /// <param name="pattern">正则表达式</param>
        public ValidatorRegex(string pattern, string errMsg)
            : base(errMsg)
        {
            mRegex = new Regex(pattern);
        }

        #region IValidator部分
        public override bool IsValid(Control controlToValidate)
        {
            if (string.IsNullOrEmpty(controlToValidate.Text.Trim()))
                return false;
            return mRegex.IsMatch(controlToValidate.Text);
        }
        #endregion


    }
}
